Page({
  /**
   * 页面的初始数据
   */
  data: {
    isfirstAdmin: false,
    isCbrc: false,
    list: [],
    agencyCode: '',
    pageNum: 1,
    pageSize: 20,
    total: '',
    statusBarHeight: '',
    navBarHeight: '',
    searchValue: '',
    loading: true,
  },
  /**
   * 方法
   */
  goOnChange(e) {
    this.setData({
      searchValue: e.detail,
    });
  },
  toMdDetail(e) {
    // 存储名单信息
    wx.navigateTo({
      url: `/sub_marketing/roll_list/roll_list?id=${e.currentTarget.dataset.id}&createUser=${e.currentTarget.dataset.man}&listName=${e.currentTarget.dataset.listname}`,
    })
  },
  scrollBottom() {
    if (this.data.list.length >= this.data.total) return
    this.data.pageNum++;
    this.getList();
    console.log('更多加载');
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    //获取系统信息， 状态栏高度为 sysInfo['statusBarHeight'];
    let sysInfo = wx.getSystemInfoSync();
    // 胶囊信息
    let menu = wx.getMenuButtonBoundingClientRect();
    // 导航栏高度
    let navBarHeight = (menu.top - sysInfo.statusBarHeight) * 2 + menu.height;
    console.log(sysInfo.statusBarHeight + navBarHeight);
    this.setData(({
      statusBarHeight: sysInfo.statusBarHeight,
      navBarHeight: navBarHeight
    }))
    // 获取产业大脑的token
    this.initCydn()
  },
  async initCydn() {
    const userInfo = wx.getStorageSync('userInfo') || ''
    const params = {
      // username: '总行经理',
      username: userInfo.phone,
      platform: "miniApp"
    }
    const res = await getApp().globalData.request_cydn(
      '/loginByUserName', params,
      "POST"
    )
    if (res.code == 200) {
      console.log(res, '产业大脑登录信息');
      wx.setStorageSync('token_cydn', res.token)
      this.getList()
    }
  },
  goback() {
    wx.navigateBack({
      delta: 1
    })
  },
  goSearch() {
    this.setData({
      pageNum: 1,
      list: []
    })
    this.getList()
  },
  async getList() {
    if (!this.data.loading) {
      wx.showLoading({
        title: "加载中",
      });
    }
    const params = {
      listName: this.data.searchValue,
      pageNum: this.data.pageNum,
      pageSize: this.data.pageSize,
    }
    console.log(params, '名单列表请求');
    const res = await getApp().globalData.request_cydn(
      '/marketing/marketingList/getList', params,
      "POST"
    )
    console.log(res, '名单列表');
    if (res.rows.length > 0) {
      this.setData({
        list: this.data.list.concat(res.rows),
        total: res.total
      })
    }
    setTimeout(function () {
      wx.hideLoading();
    }, 500);
    this.setData({
      loading: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})